package game.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class Utils {

   /**
    * Gets the size of the object in bytes.
    * @param object 
    *    The object of measurement.
    * @return
    *    -1 when error occurred.<br>
    *    Length of byte array if no error.
    */
   public static int getObjectSize(Object object) {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      ObjectOutputStream objectStream;
      try {
         objectStream = new ObjectOutputStream(byteStream);
         objectStream.writeObject(object);
         objectStream.close();
         
      } catch (IOException e) {
         return -1;
      }
      return byteStream.toByteArray().length;
   }
   
}
